﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace TCC.Framework
{
    /// <summary>
    /// 添加资源到保护列表窗口
    /// </summary>
    public class AddAssetProtectEditor : EditorWindow
    {
        Object _asset;
        string assetRemark="";
        bool isNoMove=false;
        bool isNoDelete=false;
        ProtectFileList.Data data;
        static AddAssetProtectEditor win;
        public static void OpenWin(Object asset)
        {
            win = GetWindow<AddAssetProtectEditor>();
            win.titleContent.text = "添加资源保护";
            win.minSize = new Vector2(250, 100);
            win.maxSize = new Vector2(400, 100);
            win._asset = asset;
            win.data = WindowsManager.FileList.datas.Find((d) => { return d.asset.GetInstanceID() == win._asset.GetInstanceID(); });
            if(win.data!=null)
            {
                win.assetRemark = win.data.remark;
                win.isNoMove = win.data.isNoMove;
                win.isNoDelete = win.data.isNoDelete;
            }
            win.Show();
        }

        void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("保护资源：",GUILayout.Width(60));
            _asset = EditorGUILayout.ObjectField(_asset, typeof(Object), true);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("资源备注：", GUILayout.Width(60));
            assetRemark = EditorGUILayout.TextField(assetRemark);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("保护类型：", GUILayout.Width(80));
            EditorGUILayout.LabelField("不可移动：", GUILayout.Width(60));
            isNoMove = EditorGUILayout.Toggle(isNoMove);
            EditorGUILayout.LabelField("不可删除：", GUILayout.Width(60));
            isNoDelete = EditorGUILayout.Toggle(isNoDelete);
            EditorGUILayout.EndHorizontal();

            if(GUILayout.Button("确认"))
            {
                if (_asset != null)
                {
                    if (data != null)
                    {
                        data.isNoMove = isNoMove;
                        data.isNoDelete = isNoDelete;
                        data.remark = assetRemark;
                    }
                    else
                        WindowsManager.FileList.datas.Add(new ProtectFileList.Data { asset = _asset, isNoDelete = isNoDelete, isNoMove = isNoMove, remark = assetRemark });
                    Log.Info("资源已受保护！");
                    win.Close();
                }
                else
                    Log.Info("请选择一个需要保护的资源！");
            }
        }
    }
}

